/**
 * Created by xie on 2018/3/13.
 */
angular.module('module.personalcenter')
    .controller('FileController', FileController);

FileController.$inject = ['$scope','$state','$cookies','$rootScope','FileUpload','AutherService'];

function FileController($scope, $state,$cookies, $rootScope,FileUpload,AutherService) {
    var vm = this;
    vm.changePwd=changePwd;

    if(!$cookies.get("userInfo")){
        $state.go("login");
    }
    vm.user=JSON.parse($cookies.get("userInfo"));
    vm.uploadLogo=uploadLogo;
    vm.save=save;
    vm.editchange=editchange;
    vm.sex=["男","女"]

    function changePwd(){
        $state.go("changepwd");
    }
    function editchange(){
        vm.edit = true;

    }
    function uploadLogo(file) {

        console.log(123)
        if (!file) {
            return;
        }
        FileUpload.uploadFileToUrl1(file,file.name).then(function (data) {
            vm.user.photo=data.data.faddress;
            vm.edit = true;
        }, function (error) {
            console.log(error)
        })
    }

    function save() {
        vm.edit = false;


        AutherService.updateUser(vm.user).$promise.then(function (data) {
            $cookies.put("userInfo", JSON.stringify(vm.user), {'expires': new Date(new Date().getTime() + 24 * 3600 * 1000)});

            request = data;
            console.log(request)

            return alert("保存成功");
        }, function (err) {
            console.log(err);
            return alert(err.data.msg);
        });
    }

}